﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Web.UI.WebControls;
using BLL;
using Model;
using ZedGraph;

public partial class StatisticData_ProductionStatistic_ProductionbyIsPass : System.Web.UI.Page
{
    private DateTime dt1
    {
        get { return DateTime.Parse(ViewState["starttime"].ToString()); }
        set { ViewState["starttime"] = value; }
    }
    private DateTime dt2
    {
        get { return DateTime.Parse(ViewState["stoptime"].ToString()); }
        set { ViewState["stoptime"] = value; }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        
    }
    
    protected void Button1_Click(object sender, EventArgs e)
    {
        dt1 = DateTime.Parse(this.TextBox1.Text.Trim() + " 00:00:00");
        dt2 = DateTime.Parse(this.TextBox2.Text.Trim() + " 00:00:00");
        BindIsPass_Q();
        this.ZedGraphWeb1.Visible = true;
    }

    private void BindIsPass_Q()
    {
        Test_Q t_q = new Test_Q();
        this.GridView1.DataSource = t_q.GetIsPass_Q(dt1, dt2);
        this.GridView1.DataBind();
    }

    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        this.GridView1.PageIndex = e.NewPageIndex;
        BindIsPass_Q();
    }

    protected void ZedGraphWeb1_RenderGraph(ZedGraph.Web.ZedGraphWeb webObject, System.Drawing.Graphics g, ZedGraph.MasterPane pane)
    {
        int i = 0;
        Test_Q tqt = new Test_Q();
        List<IsPass_QInfo> t_qs = (List<IsPass_QInfo>)tqt.GetIsPass_Q(dt1, dt2);

        GraphPane myPane = pane[0];

        myPane.Title.Text = "测试产品通过情况统计";

        //创建曲线
        double[] list = new double[t_qs.Count];
        string[] labels = new string[t_qs.Count];
        foreach (IsPass_QInfo t_q in t_qs)
        {
            list[i] = (double)t_q.Total;
            labels[i] = t_q.IsPass;
            i++;
        }

        switch (t_qs.Count)
        {
            case 2:
                {
                    PieItem segment0 = myPane.AddPieSlice(list[0], Color.Green, 0, labels[0]);
                    MyGraphStyle.BuildPieItem(segment0);
                    PieItem segment1 = myPane.AddPieSlice(list[1], Color.Red, 0.1, labels[1]);
                    MyGraphStyle.BuildPieItem(segment1);
                    break;
                }
            case 1:
                {
                    PieItem segment0;
                    if (labels[0] == "Pass")
                        segment0 = myPane.AddPieSlice(list[0], Color.Green, 0, labels[0]);
                    else
                        segment0 = myPane.AddPieSlice(list[0], Color.Red, 0, labels[0]);
                    MyGraphStyle.BuildPieItem(segment0);
                    break;
                }
            case 0:
                break;
        }

        MyGraphStyle.BuildpieGraphStyle(myPane);
        pane.AxisChange(g);
    }
}
